package common

import (
	"github.com/name5566/leaf/log"
	"io/ioutil"
	"math/rand"
	"os"
	"strings"
	"time"
)

var (
	nicknames []string
	avatars   []string
)

func init() {
	{
		file, err := os.Open("conf/nickname.txt")
		if err != nil {
			log.Error(err.Error())
			return
		}
		contentByte, err := ioutil.ReadAll(file)
		if err != nil {
			log.Error(err.Error())
		}
		nicknames = strings.Split(string(contentByte), "\r\n")
		log.Release("供载入%d个昵称", len(nicknames))
	}

	{
		file, err := os.Open("conf/avatar.txt")
		if err != nil {
			log.Error(err.Error())
			return
		}
		contentByte, err := ioutil.ReadAll(file)
		if err != nil {
			log.Error(err.Error())
		}
		avatars = strings.Split(string(contentByte), "\r\n")
		log.Release("供载入%d个头像", len(avatars))
	}

	rand.Seed(time.Now().Unix())
}

func GetNickname() string {
	return nicknames[rand.Intn(len(nicknames))]
}

func GetAvatar() string {
	return avatars[rand.Intn(len(avatars))]
}
